import Taro from '@tarojs/taro'
import app from '../../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            inquiry_orders: {
                offset: 0,
                length: 25,
                items: [
                     // {
                     //    id: '',
                     //    patientName: '',
                     //    created_at: '',
                     //    status: '',
                     //    order_type: '',
                     //    totalpayable:''
                     // }
                ]
            },
            menzhen_orders: {
                offset: 0,
                length: 25,
                items: [{
                    id: '',
                    patients_id_from_patient_id_name: '',
                    order_time: '',
                    status: '',
                    totalpayable: '',
                }]
            },
            operation_orders: {
                offset: 0,
                length: 25,
                items: [{
                    id: '',
                    patients_id_from_patient_id_name: '',
                    order_time: '',
                    status: '',
                    totalpayable: '',
                }]
            },
        };
        return this.state;
    },
    listInquiryOrder() {    //交易记录
        var me = this;
        var data = {offset: me.state.inquiry_orders.offset, length: me.state.inquiry_orders.length};
        var flag = true;
        if(me.beforeListInquiryOrder) {
            flag = me.beforeListInquiryOrder(data);
        }
        if(flag) {
            app.post("web/wallet/getOrderRecords", data, function(res) {
                var data = [];
                for(var i = 0; i < res.data.result.result.length; i++) {
                    var m = {
                        id: res.data.result.result[i].id,
                        order_id: res.data.result.result[i].order_id,
                        patientName: res.data.result.result[i].patientName,
                        created_at: res.data.result.result[i].created_at,
                        status: res.data.result.result[i].status,
                        order_type: res.data.result.result[i].order_type,
                        totalprice:res.data.result.result[i].totalprice
                    }
                    data.push(m);
                }
                console.log(data)
                me.setState({inquiry_orders:{offset: me.state.inquiry_orders.offset + me.state.inquiry_orders.length, length: me.state.inquiry_orders.length, items: data}});
                if(me.afterListInquiryOrder) {
                    me.afterListInquiryOrder(res);
                }
            });
        }
    },
    listMenzhenOrder() {
        var me = this;
        var data = {offset: me.state.menzhen_orders.offset, length: me.state.menzhen_orders.length};
        var flag = true;
        if(me.beforeListMenzhenOrder) {
            flag = me.beforeListMenzhenOrder(data);
        }
        if(flag) {
            app.get("api/menzhen_orders/list", data, function(res) {
                var data = [];
                for(var i = 0; i < res.data.result.data.length; i++) {
                    var m = {
                        id: res.data.result.data[i].id,
                        patients_id_from_patient_id_name: res.data.result.data[i].patients_id_from_patient_id_name,
                        order_time: res.data.result.data[i].order_time,
                        status: res.data.result.data[i].status,
                        totalpayable: res.data.result.data[i].totalpayable,
                    }
                    data.push(m);
                }
                me.setState({menzhen_orders:{offset: me.state.menzhen_orders.offset + me.state.menzhen_orders.length, length: me.menzhen_orders.length, items: data}});
                if(me.afterListMenzhenOrder) {
                    me.afterListMenzhenOrder(res);
                }
            });
        }
    },
    listOperationOrder() {
        var me = this;
        var data = {offset: me.state.operation_orders.offset, length: me.state.operation_orders.length};
        var flag = true;
        if(me.beforeListOperationOrder) {
            flag = me.beforeListOperationOrder(data);
        }
        if(flag) {
            app.get("api/operation_orders/list", data, function(res) {
                var data = [];
                for(var i = 0; i < res.data.result.data.length; i++) {
                    var m = {
                        id: res.data.result.data[i].id,
                        patients_id_from_patient_id_name: res.data.result.data[i].patients_id_from_patient_id_name,
                        order_time: res.data.result.data[i].order_time,
                        status: res.data.result.data[i].status,
                        totalpayable: res.data.result.data[i].totalpayable,
                    }
                    data.push(m);
                }
                me.setState({operation_orders:{offset: me.state.operation_orders.offset + me.state.operation_orders.length, length: me.operation_orders.length, items: data}});
                if(me.afterListOperationOrder) {
                    me.afterListOperationOrder(res);
                }
            });
        }
    },
    componentWillMount () {
        if(this.init) {
            this.init();
        }
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(name, v) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = v;
        this.setState({n: temp[names[i]]});
    },
    handleTextareaChange(name, e) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = e.target.value;
        this.setState({n: temp[names[i]]});
    },
    redirectTo(url) {
        app.redirectTo(url);
    },
    componentDidMount () {
        this.listInquiryOrder()
    },
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
